package com.wipz.eoa.iphone.officesupplies;

import java.util.HashMap;
import java.util.Map;

import com.toft.widgets.workflow.model.CompleteTaskResult;
import com.toft.widgets.workflow.utils.ConstantUtil;
import com.wipz.eoa.iphone.businessProcess.BusinessCoreServices;

public class OfficeSuppliesApplyServiceImpl extends BusinessCoreServices implements IOfficeSuppliesApplyService {

	@Override
	public Map bxSubmit(Map param) {
		//获取上下文对象
		String userCode = (String) param.get("COMMITERCODE");
		//获取ID
		String id = (String)param.get("id"); 
		//任务唯一标识taskId
		String taskId = (String) param.get("taskId");
		//处理意见
		String commentContent = (String) param.get("comment");
		//流向
		String transition = (String) param.get("transition");
		//处理类型
		String typeaccept = (String) param.get("pass");
		
		String uuitId = (String) param.get("uuitId");
		
		String PROCESSID = (String) param.get("PROCESSID");
		
		boolean pass = "true".equals(typeaccept) ? true:false;
		Map variable = new HashMap();
		variable.put(ConstantUtil.TASK_COMMNET_TYPE, ConstantUtil.APPROVE_OPERATION_PASS.equals(typeaccept) ? ConstantUtil.TASK_COMMNET_TYPE_ACCEPT : ConstantUtil.TASK_COMMNET_TYPE_REFUSE); // 意见类型
		variable.put(ConstantUtil.TASK_COMMENT_CONTENT, commentContent); // 意见内容
		variable.put(ConstantUtil.AGENCY_ID, uuitId);
		CompleteTaskResult result = this.complete(userCode, taskId, transition, variable, pass,uuitId);
		if(result == null) {
			return null;
		}
		String nextOne = result.getNextOperators();
		//流程是否结束
		if(result.isEnded()){
			String operationFlag = "officesupplies.updateProcessStatus";
			super.updateWorkflowProcessStatus("END",operationFlag,id,"",PROCESSID);
		//	this.getContext().dataResult.setMessage("true");
		}else{
			if (pass){
				Map map = new HashMap();
				map.put("NEXTAPPROVALER", nextOne);
				map.put("ID", id);
				super.update("officesupplies.updateNextapprovaler", map);
			}else{
				String operationFlag = "officesupplies.updateProcessStatus";
				super.updateWorkflowProcessStatus("BACK",operationFlag,id,nextOne,PROCESSID);
			}
		}
		Map resultMap = new HashMap();
		resultMap.put("ended", result.isEnded()+"");
		resultMap.put("back", result.isBack()+"");
		resultMap.put("nextOperators",result.getNextOperators());
		return resultMap;
	}

}
